package com.learn.demo.controller;

import com.learn.demo.entities.kafka.Message;
import com.learn.demo.provider.KafkaProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 生产者控制层
 *
 * @author banjiawei
 * @date 2022/03/16
 */
@RestController
@RequestMapping("/kafka/provider")
public class KafkaProviderController {

    @Autowired
    private KafkaProvider kafkaProvider;
    
    /**
     * 发送消息
     * @author banjiawei 
     * @date 2022/3/16
     * @param body
     * @return java.lang.String
     */
    @GetMapping("/send/{body}")
    public String sendMessage(@PathVariable("body") String body) {
        System.out.println(body);
        Message message = new Message();
        message.setContent(body);
        message.setTimestamp(new Date());
        kafkaProvider.send(message);
        return "OK";
    }
}
